package link.hwx.util;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
@SuppressWarnings("all")
@Component
public class CommonSetData implements CommandLineRunner {
    //获取本地txt文件 启动
    public static final String accountOrgID;//核算组织
    public static final String companyId; // 企业编码
    public static final String orgId;//当前组织id
    public static final String userId; //当前用户id
    public static final String orgCode;//组织编码
    public static final String userCode; //当前用户code
    public static final String serveU9Ip;//服务器ip
    public static final String serveOAIp;//OAip
    public static final String oaPrWorkflowid;//请购单流程id
    public static final String oaPayReqWorkflowid; //请款单流程id
    public static final String oaMiscShipWorkflowid;//杂发单流程id
    public static final String oaSupplierWorkflowid;//供应商流程id
    public static final String oaPurchaseOrderWorkflowid;//采购单流程id
    public static final String oaPprCpWorkflowid;//比价单流程id
    public static final String oaSupplySourceWorkflowid;//货源流程id
    public static final String oaAppid; //oaAppid
    //public static  String oaUserId = "22"; //oa加密用户id
    public static final String oaPrTableDbNameD;//oa请购单详情表
    public static final String oaPrTableMainDbNameD;//oa请购单主表
    public static final String oaMiscShipTableMainDbNameD;//oa杂发单主表
    public static final String oaMiscShipTableDbNameD;//oa杂发单详情表
    public static final String oaPayReqTableDbNameD;//oa请款单详情表
    public static final String oaPayReqTableMainDbNameD;//oa请款单主表
    public static final String oaSupplierTableMainDbNameD;//oa供应商主表
    public static final String oaSupplierTableDbNameD;//oa供应商详情表
    public static final String oaPurchaseOrderTableMainDbNameD;//采购主表
    public static final String oaPurchaseOrderTableDbNameD;//采购详情表
    public static final String oaPprCpTableMainDbNameD;//比价主表
    public static final String oaPprCpTableDbNameD;//比价详情表
    public static final String oaSupplySourceTableMainDbNameD;//货源主表
    public static final String oaSupplySourceTableDbNameD;//货源详情表
    public static final String oaAssistanceContractTableMainDbNameD;//合同主表
    public static final String oaAssistanceContractTableDbNameD;//合同详情表

    //运输需求
    public static final String oaShippingDemandWorkflowid;//运输需求流程id
    public static final String oaShippingDemandTableDbNameD;//运输需求子表
    public static final String oaShippingDemandTableMainDbNameD;//运输需求主表
    //付款申请单
    public static final String oaPayApplyWorkflowid;//付款申请单流程id
    public static final String oaPayApplyTableMainDbNameD;//付款申请单主表
    public static final String oaPayApplyTableDbNameD;//付款申请单详情表



    public static final String oaZCFilePath;//oa暂存文件路径
    public static final String srmUserCode;//srm用户账号
    public static final String srmUserPwd;//srm用户密码
    public static final String voucherno;//需求申请的单据格式
    public static final String formid;//需求申请的窗体格式
    public static final String serveSrmIp;//服务器ip
    public static final String srmPrUrlCreat;//srm请购单创建地址
    public static final String oaPoAgreementWorkflowid;//采购协议单
    public static final String oaPoAgreementTableMainDbNameD;
    public static final String oaPoAgreementTableDbNameD;
    public static final String oaArriveSignTableMainDbNameD;//到货签收
    public static final String oaArriveSignTableDbNameD;
    public static final String oaArriveSignWorkflowid;
    public static final String oaBillingTableMainDbNameD;//支票
    public static final String oaBillingTableDbNameD;
    public static final String oaBillingWorkflowid;
    public static final String oaAssistanceContractWorkflowid;
    //运输申请
    public static final String sDvoucherno;//运输申请的单据格式
    public static final String sDformid;//运输申请的窗体格式
    public static final String srmSdUrlCreat;//运输申请单创建地址
    //付款申请单
    public static final String payApplyVoucherno;//付款申请单单据格式
    public static final String payApplyFormid;//付款申请单窗体格式
    public static final String srmPayApplyUrlCreat;//付款申请单创建地址



    static {
        //String parentPath = new File(System.getProperty("user.dir")).getParent();
        String parentPath = new File(System.getProperty("user.dir")).getPath();
        Properties prop = new Properties();
        try {
            FileInputStream inputStream = new FileInputStream(new File(parentPath + "/src/main/resources/hxw.properties"));
            //properties对象读取文件输入流的数据
            prop.load(inputStream);
            inputStream.close();


          /*  File fileAl = new File(System.getProperty("user.dir") + "/src/main/resources/application.yml");
            YmlUtil.setYmlFile(fileAl);
            String u9DBUrl = prop.getProperty("u9DBUrl");
            String u9DBUsername = prop.getProperty("u9DBUsername");
            String u9DBPassword = prop.getProperty("u9DBPassword");
            String oaDBUrl = prop.getProperty("oaDBUrl");
            String oaDBUsername = prop.getProperty("oaDBUsername");
            String oaDBPassword = prop.getProperty("oaDBPassword");
            YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.U9CTest.url", u9DBUrl);
            YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.U9CTest.username", u9DBUsername);
            YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.U9CTest.password", u9DBPassword);

            YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.OAData.url", oaDBUrl);
            YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.OAData.username", oaDBUsername);
            YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.OAData.password", oaDBPassword);
*/
        } catch (IOException e) {
            e.printStackTrace();
        }
        accountOrgID = prop.getProperty("accountOrgID");
        companyId = prop.getProperty("companyId");
        orgId = prop.getProperty("orgId");
        orgCode = prop.getProperty("orgCode");
        userId = prop.getProperty("userId");
        userCode = prop.getProperty("userCode");
        serveU9Ip = prop.getProperty("serveU9Ip");
        serveOAIp = prop.getProperty("serveOAIp");
        oaPrWorkflowid = prop.getProperty("oaPrWorkflowid");
        oaMiscShipWorkflowid = prop.getProperty("oaMiscShipWorkflowid");
        oaPayReqWorkflowid = prop.getProperty("oaPayReqWorkflowid");
        oaSupplierWorkflowid = prop.getProperty("oaSupplierWorkflowid");
        oaPurchaseOrderWorkflowid = prop.getProperty("oaPurchaseOrderWorkflowid");
        oaPprCpWorkflowid = prop.getProperty("oaPprCpWorkflowid");
        oaSupplySourceWorkflowid = prop.getProperty("oaSupplySourceWorkflowid");
        oaAppid = prop.getProperty("oaAppid");
        oaPrTableDbNameD = prop.getProperty("oaPrTableDbNameD");
        oaPrTableMainDbNameD = prop.getProperty("oaPrTableMainDbNameD");
        oaMiscShipTableMainDbNameD = prop.getProperty("oaMiscShipTableMainDbNameD");
        oaMiscShipTableDbNameD = prop.getProperty("oaMiscShipTableDbNameD");
        oaPayReqTableDbNameD = prop.getProperty("oaPayReqTableDbNameD");
        oaPayReqTableMainDbNameD = prop.getProperty("oaPayReqTableMainDbNameD");
        oaSupplierTableMainDbNameD = prop.getProperty("oaSupplierTableMainDbNameD");
        oaSupplierTableDbNameD = prop.getProperty("oaSupplierTableDbNameD");
        oaPurchaseOrderTableMainDbNameD = prop.getProperty("oaPurchaseOrderTableMainDbNameD");
        oaPurchaseOrderTableDbNameD = prop.getProperty("oaPurchaseOrderTableDbNameD");
        oaPprCpTableMainDbNameD = prop.getProperty("oaPprCpTableMainDbNameD");
        oaPprCpTableDbNameD = prop.getProperty("oaPprCpTableDbNameD");
        oaSupplySourceTableMainDbNameD = prop.getProperty("oaSupplySourceTableMainDbNameD");
        oaSupplySourceTableDbNameD = prop.getProperty("oaSupplySourceTableMainDbNameD");
        //获取 运输申请配置文件
        oaShippingDemandWorkflowid=prop.getProperty("oaShippingDemandWorkflowid");
        oaShippingDemandTableDbNameD=prop.getProperty("oaShippingDemandTableDbNameD");
        oaShippingDemandTableMainDbNameD=prop.getProperty("oaShippingDemandTableMainDbNameD");
        //获取付款申请单配置文件
        oaPayApplyWorkflowid=prop.getProperty("oaPayApplyWorkflowid");
        oaPayApplyTableDbNameD=prop.getProperty("oaPayApplyTableDbNameD");
        oaPayApplyTableMainDbNameD=prop.getProperty("oaPayApplyTableMainDbNameD");

        oaZCFilePath = prop.getProperty("oaZCFilePath");
        srmUserCode = prop.getProperty("srmUserCode");
        srmUserPwd = prop.getProperty("srmUserPwd");
        voucherno = prop.getProperty("voucherno");
        formid = prop.getProperty("formid");
        serveSrmIp = prop.getProperty("serveSrmIp");
        srmPrUrlCreat = prop.getProperty("srmPrUrlCreat");
        oaPoAgreementWorkflowid = prop.getProperty("oaPoAgreementWorkflowid");
        oaPoAgreementTableMainDbNameD = prop.getProperty("oaPoAgreementTableMainDbNameD");
        oaPoAgreementTableDbNameD = prop.getProperty("oaPoAgreementTableDbNameD");
        oaArriveSignTableMainDbNameD = prop.getProperty("oaArriveSignTableMainDbNameD");
        oaArriveSignTableDbNameD = prop.getProperty("oaArriveSignTableDbNameD");
        oaArriveSignWorkflowid = prop.getProperty("oaArriveSignWorkflowid");
        oaBillingTableMainDbNameD = prop.getProperty("oaBillingTableMainDbNameD");
        oaBillingTableDbNameD = prop.getProperty("oaBillingTableDbNameD");
        oaBillingWorkflowid = prop.getProperty("oaBillingWorkflowid");
        oaAssistanceContractTableMainDbNameD = prop.getProperty("oaAssistanceContractTableMainDbNameD");
        oaAssistanceContractTableDbNameD = prop.getProperty("oaAssistanceContractTableDbNameD");
        oaAssistanceContractWorkflowid = prop.getProperty("oaAssistanceContractWorkflowid");
        //获取 运输申请配置文件
        sDvoucherno=prop.getProperty("sDvoucherno");
        sDformid=prop.getProperty("sDformid");
        srmSdUrlCreat=prop.getProperty("srmSdUrlCreat");
        //获取付款申请单配置文件
        payApplyVoucherno=prop.getProperty("payApplyVoucherno");
        payApplyFormid=prop.getProperty("payApplyFormid");
        srmPayApplyUrlCreat=prop.getProperty("srmPayApplyUrlCreat");
    }
    /* // 通过 System.getProperty("user.dir") 方式获取到项目根目录
    String projectRootDirectoryPath = System.getProperty("user.dir");
System.out.println("当前项目根目录为:\t" + projectRootDirectoryPath);
    // 通过 File 对象的 getParent() 方法获取到根目录的上级目录
    String parentPath = new File(projectRootDirectoryPath).getParent();
System.out.println("当前项目根目录的上级目录为:\t" + parentPath);
*/

    public static void setDataPropers() throws IOException {


    }

    @Override
    public void run(String... args) throws Exception {
        setDataPropers();
    }
}
